/*
 * @Author: lsjweiyi 759209794@qq.com
 * @Date: 2023-09-19 18:37:06
 * @LastEditors: lsjweiyi 759209794@qq.com
 * @LastEditTime: 2023-11-21 21:45:29
 * @FilePath: \ip-black\main.go
 * @Description: main
 */
package main

import (
	"fmt"
	ipmanage "src/ipManage"
	"src/test"
	"time"
)


func main() {
	ipStart := time.Now()
	ipList := test.CreateIp(70000000, 4) // 创建ip
	fmt.Println("创建ip耗时：", time.Since(ipStart))

	stopchan:=make(chan bool,1)
	onlyIp, _ := ipmanage.InitIpVisit(127, 60, 5,stopchan)

	startTime := time.Now()
	// 单线程运行添加ip
	for i := 0; i < len(ipList); i++ {
		onlyIp.Add(ipList[i])
	}
	//模拟第二次访问
	for i := 0; i < 10000; i++ {
		onlyIp.Add(ipList[i])
	}
	// 模拟第三次访问
	for i := 0; i < 10000; i++ {
		onlyIp.Add(ipList[i])
	}

	onlyIp.AddBanTime("0.0.0.1", -5)	// 模拟封禁5分钟
	onlyIp.AddBanTime("127.0.0.1", -128) // 模拟永封

	fmt.Println("记录ip耗时：", time.Since(startTime))
	// 等待十次巡检
	for i := 0; i < 10; i++ {
		sizeStart := time.Now()
		fmt.Println("ip队列占用内存（字节）：", onlyIp.GetSizeOf())
		fmt.Println("计算ip队列占用内存耗时：", time.Since(sizeStart))
		allStart := time.Now()
		fmt.Println("ip队列长度：", onlyIp.GetLen())
		fmt.Println("计算ip队列长度耗时：", time.Since(allStart))
		time.Sleep(time.Minute)
	}
}
